package com.zhss.redis.hash;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;

import java.io.Serializable;
import java.util.Map;

/**
 * @ClassName BlogDemo
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2021/9/10 22:14
 * @Version 1.0
 */
public class BlogDemo {
	Jedis jedis = new Jedis(new HostAndPort("121.4.79.149", 6379));

	public void publishBlog(Integer id, String title, String context, String author, String time) {
		String hashKey = "article::" + id;
		if (jedis.hexists(hashKey, title)) {
			return;
		}
		Map<String, String> map = Map.of("Id", String.valueOf(id),
				"title", title,
				"content", context,
				"author", author,
				"content_length", String.valueOf(context.length()),
				"time", time);
		jedis.hmset(hashKey, map);
	}

	public Map<String, String> getBlog(Integer id) {
		String hashKey = "article::" + id;
		return jedis.hgetAll(hashKey);
	}
}
